package com.example.service;

import com.example.entity.Articles;
import com.example.entity.User;
import com.example.mapper.ArticlesMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
科普小知识业务处理
 */
@Service
public class ArticlesService {

    @Resource
    private ArticlesMapper articlesMapper;

    public void add(Articles articles) {
        articlesMapper.insert(articles);
    }

    public void deleteById(Integer id) {
        articlesMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(Articles articles) {
        articlesMapper.updateById(articles);
    }

    public Articles selectById(Integer id) {
        return articlesMapper.selectById(id);
    }

    public List<Articles> selectAll(Articles articles) {
        return articlesMapper.selectAll(articles);
    }

    public PageInfo<Articles> selectPage(Articles articles, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Articles> articlesList = articlesMapper.selectAll(articles);
        return PageInfo.of(articlesList);
    }
}
